﻿@page "/Po/BuyDetail/Create"
@using nERP.ViewModel.Po.BuyDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@Model.Entity.Seq" />
            <Select @bind-Value="@Model.Entity.BuyId" Items="AllBuys" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g6f205c852f1b46279a458d169578dd60" />
            <BootstrapInput @bind-Value="@Model.Entity.BuyDetailCode" />
            <Select @bind-Value="@Model.Entity.GoodsId" Items="AllGoodss" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g5ea6eda99b3645edb3745d854fe34c85" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsName" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsSpec" />
            <BootstrapInput @bind-Value="@Model.Entity.GoodsUnit" />
            <BootstrapInput @bind-Value="@Model.Entity.BuyNumber" />
            <BootstrapInput @bind-Value="@Model.Entity.UnitPrice" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalPrice" />
            <BootstrapInput @bind-Value="@Model.Entity.DiscountPrice" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxRate" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxUnitPrice" />
            <BootstrapInput @bind-Value="@Model.Entity.TaxPrice" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalTaxPrice" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
            <Select @bind-Value="@Model.Entity.WarehouseId" Items="AllWarehouses" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g2ceea7eccfcf445a86d7df01715fd8da" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private BuyDetailVM Model = new BuyDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Po/BuyDetail/Create", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllBuys = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    private List<SelectedItem> AllWarehouses = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllBuys = await WtmBlazor.Api.CallItemsApi("/api/Po/BuyDetail/GetBuys");
        AllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/Po/BuyDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Po/BuyDetail/GetWarehouses");
        AllWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });

        await base.OnInitializedAsync();
    }
}
